<template>
	<view>
		
			<view class="mypage-container">
			<!-- 自定义头部 -->
			
			<!-- 个人信息模块 -->
			<view class="user-info-box">
			  <view class="avatar-box">
			    <image class="avatar" :src="user.technician_avatar"></image>
				
			    <view class="avatar-text">
			      <view class="name">
						<view  @click="getuser()">
							{{user.technician_username}}
						</view>
						
						<view class="map" @click="is_timeclick(1)">
							<u-icon name="clock" label="设定休息时间" color="#39b54a"></u-icon>
						</view>
						<view class="map" @click="addmap()">
							<u-icon name="map" label="刷新定位" color="#39b54a"></u-icon>
						</view>
				  </view>
			      <view class="desc">
					  <text>当前状态：{{user.technician_status == 1 ? '上线' :'休息中'}}</text>
					  <text class="qiehuan" @click="edit()">编辑资料</text>
					  <text style="margin-left: 5px;">浏览量 {{user.view_nums || 0}}</text>
				  </view>
				  <view class="order_time">
					  <view class="f-time" v-if="already_time > 0">
						  已服务:{{already_time}}分钟
					  </view>
					  <view class="map" @click="is_timeclick(3)">
						<u-icon name="clock" label="订单时间" color="#39b54a"></u-icon>
					  </view>
					  <view class="map" >
					  		<u-switch v-model="technician_status" @change="technicianstatus" active-color="#39b54a"></u-switch>
					  </view>
				  </view>
				  <u-icon name="map" color="#000"  labelColor="#000" :label="city_str" @click="cityshow = true"></u-icon>
			    </view>
			  </view>
			 
			</view>
			
			<!-- 粉丝 -->
			<view class="fans-box">
			  <view class="fans-item" @click="toUrl('/pages/user/wallet/score-balance?type=money')">
			    <view class="fans-num">{{user.total_income}}</view>
			    <view class="fans-text">总收益</view>
			  </view>
			  <view class="fans-item" @click="orderlist(0)">
			    <view class="fans-num">{{user.service_nums}}</view>
			    <view class="fans-text">累计单量</view>
			  </view>
			  <view class="fans-item" @click="orderlist(1)">
			    <view class="fans-num">{{user.today_service_nums}}</view>
			      <view class="fans-text">当日单量</view>
			  </view>
			  <view class="fans-item" @click="zaixianshichang()">
			    <view class="fans-num">{{user.online_duration || 0}}</view>
			    <view class="fans-text">在线时长</view>
			  </view>
			</view>
			
			<view class="fans-box" style="margin-top: 15px;">
			  <view class="fans-item" @click="toUrl('/pages/user/wallet/score-balance?type=money&tab=project_income')">
			    <view class="fans-num">{{user.project_income}}</view>
			    <view class="fans-text">项目收益</view>
			  </view>
			  <view class="fans-item" @click="toUrl('/pages/user/wallet/score-balance?type=money&tab=fare_income')">
			    <view class="fans-num">{{user.fare_income}}</view>
			    <view class="fans-text">车费收益</view>
			  </view>
			<view class="fans-item" @click="toUrl('/pages/user/wallet/score-balance?type=money&tab=jz_income')">
			  <view class="fans-num">{{user.jz_income}}</view>
			  <view class="fans-text">加钟收益</view>
			</view>
			</view>
			
			<view class="mar">
				<view class="dfx">
					<image src="../../static/images/11.png" class="left" @click="bodadianhua()"></image>
					<image src="../../static/images/222.png" class="right" @click="toUrl('/pages/goods/comment/comment-list?technician_id=' + user.uid)"></image>
				</view>
			</view>
			<!-- 常用功能 -->
			<view class="usual-ability-box">
			  <view class="usual-ability-title">
			    常用功能
			  </view>
			  <view class="usual-ability-content">
			    <!--<view class="usual-ability-item" @click="toUrl('/pages/jishi/xiangche')">
			      <image src="../../static/images/xiangche.png"></image>
			      <view class="usual-ability-item-text">
			        我的生活照
			      </view>
			    </view>-->
			    <view class="usual-ability-item" @click="toUrl('/pages/user/wallet/score-balance?type=money')">
			        <image src="../../static/images/shouru.png"></image>
			      <view class="usual-ability-item-text">
			        我的收益
			      </view>
			    </view>
			    <view class="usual-ability-item" @click="toUrl('/pages/app/commission/team?type=1')">
			       <image src="../../static/images/yd.png"></image>
			      <view class="usual-ability-item-text">
			        我的团队
			      </view>
			    </view>
			    <view class="usual-ability-item" @click="toUrl('/pages/goods/comment/comment-list?technician_id=' + user.uid)">
			       <image src="../../static/tab/js_s.png"></image>
			      <view class="usual-ability-item-text">
			        评价管理
			      </view>
			    </view>
				<view class="usual-ability-item" @click="toUrl('/pages/user/wallet/withdraw?type=2')">
				   <image src="../../static/images/tixian.png"></image>
				  <view class="usual-ability-item-text">
				    申请提现
				  </view>
				</view>
				<view class="usual-ability-item" @click="toUrl('/pages/user/wallet/withdraw-log')">
				   <image src="../../static/images/tixianliebao.png"></image>
				  <view class="usual-ability-item-text">
				    提现明细
				  </view>
				</view>
				<view class="usual-ability-item" @click="toUrl('/pages/user/wallet/score-balance?type=score&source=0')">
				   <image src="../../static/images/tixianliebao.png"></image>
				  <view class="usual-ability-item-text">
				    积分明细
				  </view>
				</view>
				<view class="usual-ability-item" @click="toUrl('/pages/user/wallet/score-balance?type=money&tab=fare_income')">
				   <image src="../../static/images/tixianliebao.png"></image>
				  <view class="usual-ability-item-text">
				    车费明细
				  </view>
				</view>
				<!--<view class="usual-ability-item" @click="toUrl('/pages/index/fuwuxiangmu')">
				   <image src="../../static/images/tixianliebao.png"></image>
				  <view class="usual-ability-item-text">
				    服务项目
				  </view>
				</view>-->
			  </view>
			</view>
		</view>
		<!-- 与包裹页面所有内容的元素u-page同级，且在它的下方 -->
		<u-tabbar v-model="current" :list="list" ></u-tabbar>
		<time-selector @selectTime="selectTimeEvent"  selectedTabColor="#39b54a" v-if="is_time" :types="types"
		selectedItemColor="#39b54a" disableText="休息" @clonse="clonse"></time-selector>
	</view>
</template>

<script>
	import timeSelector from '@/components/xiujun-time-selector/index.vue';
	import { mapMutations, mapActions, mapState, mapGetters } from "vuex";
	import Auth from "@/shopro/permission/index.js";
	export default {
		components: {timeSelector},
		data() {
			return {
				str:'上班',
				cityshow:false,
				city_str:"正在定位",
				already_time:-1,
				types:1,
				is_time:false,
				technician_status:false,
				user:{
			
				},
				model: {
					refusal_order_time:'',//休息时间
				},	
				list: [{
						iconPath: "home",
						selectedIconPath: "home-fill",
						text: '主页',
						customIcon: false,
						pagePath:"/pages/teacher/index"
						
					},
					{
						iconPath: "list",
						count: 0,
						selectedIconPath: "photo-fill",
						text: '订单',
						customIcon: false,
						pagePath:"/pages/jishi/order"
					}
				],
				current: 0
			}
		},
		computed: {
			...mapGetters(['isLogin', 'authType','userInfo']),
		},	
		onLoad() {
			let that = this
			setInterval(function() {
			  // 这里是需要执行的任务代码
				that.getUpdateTime()
			}, 10000); // 60000毫秒等于1分钟
			this.getinit();
		},
		onShow() {
			this.getUpdateTime()
			this.addmap()
		},
		methods: {
			technicianstatus(e){
				this.qiehuan(e)
			},
			is_timeclick(type){
				this.types = type.toString()
				this.is_time = true
			},
			getUpdateTime(){
				let that = this
				that.$http('technician.calculateAlreadyServiceTime', {uid:this.userInfo.uid}, '提交中...').then(res => {
					that.already_time = res.data.already_time
					that.addmap()
				})
			},
			clonse(){
				let that = this;
				this.is_time = false
				if(that.model.refusal_order_time && that.types == 1){
					that.model.refusal_order_time = JSON.stringify(that.model.refusal_order_time)
					that.isFormEnd = false;
					that.$http('technician.updateRefusalTime', that.model, '提交中...').then(res => {
						that.model.refusal_order_time = ''
						that.getinit();
						that.$u.toast('设定成功');
					})
				}
			},
			selectTimeEvent(e){
				
				this.model.refusal_order_time = e
			},	
			async addmap(){
				
				let that = this
				uni.showLoading({
				  title: '定位中...',
				  mask: true
				});
				
				let authState = await new Auth("userLocation").check();
				// #ifdef MP ||　APP-VUE
				authState &&
				uni.getLocation({
				  type: "gcj02",
				  geocode:true,
				  success: (res) => {
					let lng = res.longitude;
					let lat = res.latitude;
					uni.hideLoading();
					uni.setStorageSync('lat',lat)
					uni.setStorageSync('lng',lng)
					that.updatejishidingwei(lat,lng)
					that.getaddresslatlng(lat,lng)
				  },
				  fail: (err) => {
				    console.log("确认订单自提位置：", err);
				  },
				});
				// #endif
				// #ifdef H5
				console.log('开始定位')
				uni.getLocation({
				  type: "gcj02",
				  geocode:true,
				  success: (res) => {
					let lng = res.longitude;
					let lat = res.latitude;
					uni.hideLoading();
					uni.setStorageSync('lat',lat)
					uni.setStorageSync('lng',lng)
					that.updatejishidingwei(lat,lng)
					that.getaddresslatlng(lat,lng)
				  },
				  fail: (err) => {
				    console.log("确认订单自提位置：", err);
				  },
				});
				// #endif
				
				
				
			},
			getaddresslatlng(lat,lng){
					  let  that = this
					  that.$http(
					      'technician.getaddresslatlng',
					      {
							  lat:lat,
							  lng:lng
						  },'加载中...'
			    ).then(res => {
							that.city_str = res.data
					  })	  
			},
			updatejishidingwei(lat,lng){
				let that = this;
				that.$http('technician.updateLocation', {lat:lat,lng:lng}, '更新中...').then(res => {
					//that.$u.toast('更新成功');
				})
			},
			orderlist(type){
				uni.navigateTo({
					url: '/pages/jishi/order?type=' + type
				})
			},
			zaixianshichang(){
				uni.navigateTo({
					url: '/pages/jishi/zaixianshichang'
				})
			},
			getuser(){
				uni.navigateTo({
					url: '/pages/jishi/getjishi'
				})
			},
			getinit(){
				let that = this;
				let userInfo = uni.getStorageSync('userInfo')
				that.$http('technician.getTechnicianInfoDetail', {}, '获取中...').then(res => {
					that.user = res.data
					if(typeof(that.user.refusal_order_time)!='undefined'){
						uni.setStorageSync('refusal_order_time',that.user.refusal_order_time)
					}
					if(typeof(that.user.refusal_order_order_time)!='undefined'){
						uni.setStorageSync('refusal_order_order_time',that.user.refusal_order_order_time)
					}
					console.log(that.user.technician_status)
					this.technician_status = that.user.technician_status==1?true:false
					//that.list[1].count = res.data.service_nums
					
				})	
			},
			edit(){
				uni.navigateTo({
					url: '/pages/jishi/edituser'
				})
			},
			qiehuan(e){
				let status = e?1:0;
				this.$http('user.operationTechnicianStatus', {
					status:status
				}).then(res => {
					this.$u.toast(res.msg);
					if(res.code = 1){
						this.user.technician_status = status
					}
				})
			},
			bodadianhua(){
				uni.makePhoneCall({
					// 手机号
					phoneNumber: this.user.on_duty_phone,
					// 成功回调
					success: (res) => {
					},
					// 失败回调
					fail: (res) => {
					}
				});
			},
			toUrl(url){
				uni.navigateTo({
					url: url
				})
			},
			getList() {
				this.$http('addons/shopro/user', {
				}).then(res => {
					this.user = res.data
				})	
			}
		}		
	}
</script>
<style>
  .head {
    
  }
  /* 用户信息部分 */
  .user-info-box {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    width: 100%;

  }
  
  .avatar-box {
		display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        align-items: center;
        padding-left: 21px;
        margin-bottom: 45px;
  }
  
  .avatar-box .avatar {
    width: 116rpx;
    height: 116rpx;
    border-radius: 116rpx;
  }
  
  .avatar-box .avatar-text {
    padding-left: 20rpx;
  }
  
  .avatar-text .name {
    font-size: 40rpx;
    font-weight: 500;
    color: #000002;
	display: flex;
	justify-content: space-between;
  }
  
  .avatar-text .desc {
    color: #a0a1a3;
    padding-top: 10rpx;
    font-size: 26rpx;
  }
  .arrow-box {
    width: 20rpx;
    height: 20rpx;
    border-top: 3rpx solid #a9acb3;
    border-right: 3rpx solid #a9acb3;
    transform: rotate(45deg);
    margin-right: 40rpx;
  }
  .fans-box {
    display: flex;
    justify-content: space-around;
    align-items: center;
  }
  .fans-item {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
  .fans-num {
    font-size: 30rpx;
    font-weight: bold;
    color: #000002;
    margin-bottom: 20rpx;
  }
  .fans-text {
    font-size: 25rpx;
    color: #919294;
  }
  .usual-ability-box {
    margin-top: 30rpx;
    background-color: #fff;
    padding: 35rpx 55rpx;
  }
  /* 常用功能 */
  .usual-ability-title {
    margin-top: 15rpx;
    font-size: 25rpx;
    font-weight: 700;
    margin-bottom: 30rpx;
  }
  .usual-ability-content {
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
  }
  .usual-ability-item {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 160rpx;
    height: 160rpx;
  }
  .usual-ability-item image {
    width: 40rpx;
    height: 40rpx;
    margin-bottom: 25rpx;
  }
  .usual-ability-item-text {
    font-size: 25rpx;
    font-weight: 400;
  }
  .mypage-container {
	background: white;
	padding-top: 15px;
	height: 100vh;
  }
  .qiehuan {
	  margin-left: 35px;
	      background: #39b54a;
	      color: white;
	      padding: 5px;
	      border-radius: 5px;
  }
  .left {
	  height: 70px;
	  width: 160px;
	  border-radius: 10px;
  }
  .right {
  	  height: 70px;
  	  width: 160px;
  	  border-radius: 10px;
  }
  .dfx {
	  display: flex;
	  justify-content: space-between;
	  width: 90%;
	  margin: auto;
  }
  .mar {
	  margin-top: 30px;
  }
  .edit {
	  font-size: 12px;
	  margin-left: 20px;
	  color: red;
  }
  .f-time {
	color: #39b54a;
	font-size: 14px;
  }
  .order_time {
	  display: flex;
	  justify-content: space-between;
	  margin-top: 20px;
  }
</style>